package cn.buk.tms.factory;

import cn.buk.tms.entity.misc.Customer;
import cn.buk.tms.common.dto.CustomerDto;
import org.springframework.beans.BeanUtils;

public class CustomerDtoFactory {

  public static CustomerDto createByCustomer(Customer c) {
    CustomerDto o = new CustomerDto();
    if (c != null) {
      BeanUtils.copyProperties(c, o);

      o.setName(c.getVipName());
      try {
        o.setEnterpriseId(c.getCustomerEnterpriseId());
      } catch (NumberFormatException ex) {
//        logger.error("customer: " + c.getId() + ", " + c.getCustomerEnterpriseId());
      }
    } else {
      o.setId(0);
      o.setName("散客");
      o.setCustomerCode("");
    }

    return o;
  }
}
